<?php
require_once(APPPATH . '/models/table_model.php');

class CMF_Artist_model extends Table_model{
	function CMF_Artist_model(){
		parent::Table_model();
		
		$this->table = 'Artist_Users';
		$this->table_name = 'Artists';
		
		$this->id_field = 'id';
		
		$this->ci->load->model('artist_model');
		$this->ci->load->helper('url');
		$id = array_pop(explode('/', current_url()));
		$id = is_numeric($id)? $id:null;
		$artist_options = $this->ci->artist_model->getOptions($id);
		
		/* can add fields that are just html elements for headers */
		$this->fields = array(
			'id'					=> array(
												'name' 		=> 'Artist ID',
												'view'		=> false,
												'edit'		=> array( 
																'func' 		=> 'form_hidden',
																'params'	=> null,
																'label'		=> false,
																'hidden'	=> true
															)
											),
			'archive_artist_id'			=> array(
												'name'	=> 'Archive Artist',
												'view'	=> array(
																'func' => array($this->ci->artist_model, 'getName'),
																'params' => array()
														),
												'sort'	=> "select an.agent_name from Agent as a LEFT JOIN Agent_Name as an ON a.agent_id = an.agent_id where a.agent_id = archive_artist_id LIMIT 1",
												'edit'	=> array(
															'func'		=> array('Form_wrapper', 'form_dropdown_wrapper'),
															'params' 	=> array( 
																			array('id' => 'archive_artist_id'),
																			$artist_options
																		),
															'label'		=> true
														),
												'rules'	=> ''
											),
			'username'					=> array(
												'name' 	=> 'Username',
												'view'	=> true,
												'sort'	=> true,
												'edit'	=> array(
															'func'		=> array('Form_wrapper', 'form_input_wrapper'),
															'params'	=> array( array('id' => 'username', 'autocomplete' => 'off') ),
															'label'		=> true,
															'help'		=> 'Username is your email address you have registered with AAAC.'
														),
												'rules'	=> 'trim|required|valid_email'
											),
			'password'			=> array(
												'name' 	=> 'Password',
												'view'	=> false,
												'sort'	=> false,
												'edit'	=> array(
															'func'		=> array('Form_wrapper', 'form_input_wrapper'),
															'params'	=> array( array('id' => 'password', 'type' => 'password', 'autocomplete' => 'off') ),
															'label'		=> true
														),
												'rules'	=> 'trim|required|sha1'
											),
			'password_confirmation'			=> array(
												'name' 	=> 'Password Confirmation',
												'view'	=> false,
												'sort'	=> false,
												'edit'	=> array(
															'func'		=> array('Form_wrapper', 'form_input_wrapper'),
															'params'	=> array( array('id' => 'password_confirmation', 'type' => 'password', 'autocomplete' => 'off') ),
															'label'		=> true
														),
												'rules'	=> 'trim|required|sha1|matches[password]'
											),
			'active'						=> array(
												'name'	=> 'User Active',
												'view'	=> true,
												'sort'	=> true,
												'edit'	=> array(
															'func'		=> array('Form_wrapper', 'form_checkbox_wrapper'),
															'params'	=> array( array('id' => 'active', 'checked' => 'checked')),
															'label'		=> true
														),
												'rules'	=> ''
											)
		);
	}
	
	/*function getItem( $id, $array = false){
		$item = parent::getItem( $id, $array);
		return $item;
	}*/
}
?>